<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.Updata"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.DBtools"%>
<%@page import="com.Updata"%>
<%@page import="java.sql.*"%>
<%@page import="com.Datetools"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!-- 这是一个打卡数据统计页面 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
 	<%@ include file="../bootstrap.jsp"%>
	<title>打卡数据</title>
	<link href="../Style.css" rel="stylesheet" type="text/css" />
</head>

<h3 align="left"">今日打卡</h3>
<body>
<style>td{text-align: center;}</style>
<%

//new Updata().start();//每天导入数据
//更新打卡数据

String date= new Datetools().getDate();

/* SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
Date date2=df1.parse(date+" "+"00:00:00");
System.out.println("date2"+date2); */

System.out.println("date"+date);
ResultSet rs1= new DBtools().query("select * from teachercheck where Date >"+date);
String TeaId="",Date="",IsNuclein="否",IsCheck="已完成";
int r=0;
while(rs1.next()){
	TeaId=rs1.getString("TeaId");
	Date=rs1.getString("Date");
	IsNuclein=rs1.getString("IsNuclein");
	r= new DBtools().execute("update teastatistics set Date='"+Date+"', IsCheck='"+IsCheck+"',IsTested='"+(IsNuclein.equals("是")? "已完成":"未完成" )+"' where TeaId ='"+TeaId+"' and Date >'"+date+"'");
}



System.out.println("rs1"+rs1);

/* Date nowtime= new Datetools().getTime();
String nowtime2= new Datetools().toString(nowtime);
Date nowtime3= new Datetools().toTime(nowtime2);

 */
 

//连接数据库
Class.forName("org.mariadb.jdbc.Driver");
String url = "jdbc:mariadb://localhost:3306/epidemicmanagement";//地址+接口+数据库名
Connection conn = DriverManager.getConnection(url,"root","123456");
Statement stmt = conn.createStatement();

//request.getSession().setAttribute("depname","计人");//后面更改-----------------后面更改-------------后面更改-------后面更改-----------------------------
String DepName=(String)request.getSession().getAttribute("UserName");
ResultSet rs = stmt.executeQuery("select * from teastatistics where (Date ='"+date+"' or Date >'"+date+"') and DepName like '%"+DepName+"%' order by Date  desc  ");//尚未完善，更改
//计算起止位置
rs.last();
int count=rs.getRow();

int end;
int items=8;

//获取当前页码
int pg=1;
if(count %items!=0 ){
	end=count/items+1;
}
else end=count/items;
/* System.out.println("总计数："+count);
out.println("<br>总计数："+count+"<br>"); */

String p=request.getParameter("p");
if(p!=null && Integer.parseInt(p)>0 && Integer.parseInt(p) <=end){
	pg=Integer.parseInt(p);
}

int start =(pg-1)*items;
int limit=pg*items<count ?pg*items :count;
if(start>0){
	 rs.absolute(start);
}else{
	 rs.beforeFirst();
}
System.out.println("区间:"+start+"-"+limit);

if(count %items!=0 ){
	end=count/items+1;
}
else end=count/items;
/* out.println("区间:"+start+"-"+limit+"<br>"); */

//定位循环下面的while
//计算连接下面的超链接 
%>
<hr>
<style> div{ margin: 20px}</style>
<div>
<nav class="navbar navbar-light bg-light">
			<ul class="pagination">
				<!-- 显示上一页和下一页分页按钮 -->
				<li class="page-item"><a class="page-link" href="checkstata.jsp?p=<%=1 %>">首页</a></li>			
				<li class="page-item "><a class="page-link" href="checkstata.jsp?p=<%=pg-1%>">上一页</a></li>
				
				<li class="page-item"><a class="page-link" href="checkstata.jsp?p=<%=pg+1 %>">下一页</a></li>
				
				<li class="page-item"><a class="page-link"  href="checkstata.jsp?p=<%=end %>">尾页</a></li>
                <li class="page-link"><% out.println("第"+pg+"页/"+end+"页，共"+count+"条记录！");%></li>
			</ul>
			<!-- <a align="right" href="#">在此新增学院账号</a> -->
		</nav>
<%-- <table border="0" >
<tr>
 <td class="page-item "> <a href="checkstata.jsp?p=<%=1 %>">首页 </a></td>
 <td class="page-item "><a href="checkstata.jsp?p=<%=pg-1%>">上一页 </a></td>
 <td ><a href="checkstata.jsp?p=<%=pg+1 %>">下一页></a></td>
 <td ><a href="checkstata.jsp?p=<%=end %>">尾页 </a></td>
 <td><% out.println("第"+pg+"页/"+end+"页，共"+count+"条记录！");%></td>
</tr>
</table>
 --%>
<table width="80%" align="center" class="table table-striped">
 <tr align="center" >
            <th>教师工号</th>
            <th>教师姓名</th>       
            <th>日期</th>
            <th>学院</th>
            <th>打卡情况</th>
            <th>异常备注</th>
            <th>操作</th>
        </tr>
    
<%while(rs.next() && rs.getRow()<=limit){
	TeaId = rs.getString("TeaId");
	 Date = rs.getString("Date");
%>
<tr >	
	<td align="center" > <%=rs.getString("TeaId")%>  </td>
	<td> <%=rs.getString("TeaName")%>  </td>
	<td> <%=rs.getString("Date")%> </td>
	<td> <%=rs.getString("DepName")%>  </td>
	<td> <%=rs.getString("IsCheck")%>  </td>
	
	<td><%=rs.getString("IsUnusual")%></td>
	<td align="center"><a href="checkremark.jsp?TeaId=<%=TeaId%>&Date=<%=Date%>">添加备注</a></td>
</tr>
<%}%>
</table>
<br>
</div>
<% 
stmt.close();
conn.close();
rs.close();
%>
</body>
</html>